<!--添加修改角色信息-->
<template>
    <a-modal v-model="showAddTable" :mask-closable="false" :closable="false" :width="900"
             :title="title ? '新增实验室' : '编辑实验室'"
             :maskClosable="false"
             :destroyOnClose="true">
        <a-form :form="form" @keydown.native.enter.prevent="saveApply" class="modelSearch">
            <a-form-item label="建筑物名称：" prop="buildName" v-bind="formStyle">
                <a-input
                        placeholder="请输入建筑物名称" ref="re"
                        v-decorator="[
                        'buildName',
                        {
                            rules: [
                                { required: true, message: '请输入汉字、字母、数字、_或-字符' },
                                { validator: this.verify.validateName.bind(this) }
                            ],
                            getValueFromEvent: event => {
                                return this.verify.formalSpace(event)
                            }
                        }
                    ]"
                />
            </a-form-item>
          <a-form-item label="建筑物代码：" prop="buildCode" v-bind="formStyle">
            <a-input
                placeholder="请输入建筑物代码" ref="re"
                v-decorator="[
                        'buildCode',
                        {
                            rules: [
                                { required: true, message: '请输入汉字、字母、数字、_或-字符' },
                                { validator: this.verify.validateName.bind(this) }
                            ],
                            getValueFromEvent: event => {
                                return this.verify.formalSpace(event)
                            }
                        }
                    ]"
            />
          </a-form-item>
          <a-form-item label="实验室名称：" prop="name" v-bind="formStyle">
            <a-input
                placeholder="请输入实验室名称" ref="re"
                v-decorator="[
                        'name',
                        {
                            rules: [
                                { required: true, message: '请输入汉字、字母、数字、_或-字符' },
                                { validator: this.verify.validateName.bind(this) }
                            ],
                            getValueFromEvent: event => {
                                return this.verify.formalSpace(event)
                            }
                        }
                    ]"
            />
          </a-form-item>
          <a-form-item label="房间号：" prop="roomCode" v-bind="formStyle">
            <a-input
                placeholder="请输入房间号" ref="re"
                v-decorator="[
                        'roomCode',
                        {
                            rules: [
                                { required: true, message: '请输入正整数' },
                                { validator: this.verify.validateInteger.bind(this) }
                            ],
                            getValueFromEvent: event => {
                                return this.verify.formalSpace(event)
                            }
                        }
                    ]"
            />
          </a-form-item>
          <a-form-item label="实验桌数量：" prop="diskNum" v-bind="formStyle">
            <a-input
                placeholder="请输入实验桌数量" ref="re"
                v-decorator="[
                        'diskNum',
                        {
                            rules: [
                                { required: true, message: '请输入正整数' },
                                { validator: this.verify.validateInteger.bind(this) }
                            ],
                            getValueFromEvent: event => {
                                return this.verify.formalSpace(event)
                            }
                        }
                    ]"
            />
          </a-form-item>
        </a-form>
        <div slot="footer">
            <a-button type="default" size="default" @click="cancelApply()">取消</a-button>
            <a-button type="primary" size="default" @click="saveApply()">确定</a-button>
        </div>
    </a-modal>
</template>

<script>
    import verify from 'libs/verify'
    import AFormItem from 'ant-design-vue/es/form/FormItem'
    export default {
        name: 'addEdit',
        components: {
            AFormItem,
        },
        data () {
            return {
                verify,
                form: this.$form.createForm(this),
                showAddTable: false,
                input: false,
            }
        },
        computed: {
            formStyle() {
                return this.$store.state.common.formStyle
            }
        },
        props: {

            title: {
                type: Boolean,
                required: true
            },
          labDTO:{
            type: Object,
            required: true
          }
        },
        watch: {

        },
        methods: {
            /**
             * Function    : saveApply
             * Description : 打开弹框
             * Input       : none
             * Return      : none
             */
            showModal () {
                this.showAddTable = true
            },
            /**
             * Function    : showEdit
             * Description : 编辑时显示
             * Input       : opt单个所有数据
             * Return      : none
             */
            showEdit ( opt ) {
                this.showAddTable = true
                this.id = opt.recordId
                this.$nextTick (() => {
                    this.form.setFieldsValue (this.$pick (opt, [ 'name', 'buildName', 'buildCode','roomCode','diskNum' ]))
                })
            },

            /**
             * Function    : saveApply
             * Description : 角色信息新增、编辑保存
             * Input       : name
             * Return      : none
             */
            saveApply ( ) {
                this.form.validateFields((err, value) => {
                    if (!err) {
                        let para = Object.assign ({}, this.sysRoleDTO)
                        para.name = value.name
                        para.buildName = value.buildName
                        para.buildCode = value.buildCode
                        para.roomCode = value.roomCode
                        para.diskNum = value.diskNum
                      if (!this.title){
                        para.recordId = this.id
                      }
                      this.$store.dispatch ('saveLabAct', para).then (response => {
                          this.showAddTable = false
                          if (response.code === 0) {
                              this.$emit ('init')
                              this.$message.success (response.message)
                          } else {
                              this.$message.error (response.message)
                          }
                      })
                    }
                })
            },

            /**
             * Function    : cancelApply
             * Description : 取消弹出框
             * Input       : val
             * Return      : none
             */
            cancelApply ( ) {
                this.showAddTable = false
                let _this = this
                setTimeout(function() {
                    _this.form.resetFields()
                }, 100)
            },


        },

        created () {

        }
    }
</script>
